﻿using GurLoader.Service.ImgurTaskBuilder;
using Imgur.Net;

namespace GurLoader.Util
{
    public static class LinkHelper
    {
        private const string AlbumInfoLinkTemplate = "http://imgur.com/a/{0}";
        private const string ImageInfoLinkTemplate = "http://imgur.com/{0}";

        public static string GetLinkUrl(object o)
        {
            if (o == null)
                return string.Empty;

            if (o.GetType() == typeof (AlbumUploadResult))
                return GetLinkUrl(((AlbumUploadResult) o).AlbumInfo);

            if (o.GetType() == typeof (ImageUploadResult))
                return GetLinkUrl(((ImageUploadResult) o).ImageInfo);

           return string.Empty;
        }

        public static string GetLinkUrl(ImageInfo imageInfo)
        {
            if (! string.IsNullOrEmpty(imageInfo.Link))
                return imageInfo.Link;

            return string.Format(ImageInfoLinkTemplate, imageInfo.Id);
        }

        public static string GetLinkUrl(AlbumInfo albumInfo)
        {
            if (! string.IsNullOrEmpty(albumInfo.Link))
                return albumInfo.Link;

            return string.Format(AlbumInfoLinkTemplate, albumInfo.Id);
        }
    }
}
